<%@page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/jsp/comm_css_include.jsp"%>
<!doctype html>
<html>
<head></head>
<body class="gray-bg">

	<!-- 隐藏域 -->
	<input type="hidden" value="${id}" id="busiId" name="busiId" />
	<!-- 隐藏域 -->

	<div class="container creditbody">
		<div class="iboxtitle">
			<span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;&nbsp;贷中业务&nbsp;&gt;&nbsp;退贷登记</span>
			<a href="javascript:void(0)"></a>
		</div>
		<div class="ibox-content ibox-con">
			<div class="buttonfixed">
				<button type="button" class="btn dpbtn_blue btnaplly"
					onclick="allocation();">确认退贷</button>
			</div>
			<form class="form-horizontal" id="commentForm">
				<%@include file="/jsp/common_yw_with_loan_include.jsp"%>
				<div class="business-manwife">退贷登记</div>
				<div class="padding-nono">
					<table cellpadding="0" cellspacing="0" border="0"
						class="buyinfor-table">
						<tr>
							<td align="right"><label class="control-label np">退贷时间：</label>
							</td>
							<td><input id="date_exit" name="date_exit" required="required" placeholder="退贷时间(必填)" class="laydate-icon form-control" onclick="laydate()" /></td>

							<td align="right"><label class="control-label np">退贷原因：</label>
							</td>
							<td class="td-width"><select id="reason_exit" name="reason_exit" class="select-control" required="required"> &nbsp;
							</select></td>
						</tr>
						<!--  
				<tr>
					<td align="right">
						<label class="control-label np">垫款退回时间：</label>
					</td>
					<td>
						<input id="time_arrive" name="time_arrive" placeholder="" class="form-control" readonly="readonly" onclick="laydate()"/>
					</td>
					<td align="right">
						<label class="control-label" style="color:red">垫款尚未退回！</label>
					</td>
				</tr>
				-->
						<tr>
							<td align="right" valign="top"><label
								class="control-label np">退贷备注：</label></td>
							<td colspan="3"><textarea id="remarks" rows="2"
									cols="remarks" class="form-control"></textarea></td>
						</tr>
					</table>
				</div>
			</form>
		</div>
		<!-- public quote -->
		<%@include file="/jsp/comm_js_include.jsp"%>

		<!-- layerDate plugin javascript -->
		<script src="${basePath}/js/plugins/layer/laydate/laydate.js"></script>

		<script type="text/javascript">
		
       $(function(){
    	   
    	   initData();
       });
       
       var initData = function()
       {
    	  var busiId = $('#busiId').val();
    	  
    	  $.dpAjax({
    		show:false,
   	   		url:'${basePath}/DaiZhongYwController/getDataDictionaryList',
   	   		data:{
   	   			"busiId":busiId
   	   		},
   			success: function(datas){
	   		 	  if(datas.flag == "100100"){
	   		 		
	   		 		  var d = datas.LoanExitReason_Result;
	   		 		  var objs = '';
		   		 	  for(var key in d)
		   		 	  {
		   		 		objs += '<option value="'+key+'">'+d[key]+'</option>';
		   		 	  }  
	   		 		  $('#reason_exit').html(objs);
	   		 		  
	   		 		  var d = datas.result;
	   		 		  if(null != d)
	   		 		  {
	   		 			$('#time_arrive').val(d.timeArrive);
	   		 		  }
	   				  return;
	   			  }
	   			  if(datas.flag == "100200"){
	   				  alert(JSON.stringify(datas));
	   	              return;
	   	          }
	   			  layer.msg(datas.message, {icon: 2});
	   			}
   	   	   });
    	  
    	  $("#commentForm").validate({
             //重写showErrors
             showErrors: function (errorMap, errorList) {
                 
                 $.each(errorList, function (i, v) {
                     layer.tips(v.message, v.element, { time: 1500 });
                     return false;
                 });  
             },
             /* 失去焦点时验证 */
             onfocusout: function(element) { $(element).valid(); },
             /*  键盘抬起不验证 */
             onkeyup:false,
         });
       }
       
       var allocation = function()
       {
    	   var busiId = $('#busiId').val();
    	   var date_exit = $('#date_exit').val();
    	   var reason_exit = $('#reason_exit').val();
    	   var remarks = $('#remarks').val();
    	   var cus_id = '${current_user_key.id}';
    	   
    	   var validstatus = $("#commentForm").valid();
 	       if(!validstatus){
 	    	  layer.msg("有验证未通过，请检查！", {icon: 5});
 	    	  return;
 	       }
    	 //询问框
    	   layer.confirm('退贷登记就绪，是否确认执行？操作人：<span style="color:#BD1723;">${current_user_key.uname}</span>', {
    	     btn: ['确定','取消'] //按钮
    	   }, function(){
    		   layer.closeAll();
    		   $.dpAjax({
          	   		url:'${basePath}/DaiZhongYwController/daiZhongYwTuiDaiBiao',
          	   		data:{
          	   			"busiId":busiId,
          	   			"cusId":cus_id,
          	   			"dateExit":date_exit,
          	   			"reasonExit":reason_exit,
   	       	   			"id":busiId,
   	  	   				"busiStatus":"9810"
          	   		},
          			success: function(datas){
      	   		 	  if(datas.flag == "100100"){
      	   		 		  layer.msg("退贷执行成功！", {icon: 6});
		      	   		  setTimeout(function () {
		      	   			window.location.href = "${basePath}/web/daiZhongYw/returnGoodsList.jsp";
		      	   		  }, 3000);
      	   				  return;
      	   			  }
      	   			  if(datas.flag == "100200"){
      	   				  alert(JSON.stringify(datas));
      	   	              return;
      	   	          }
      	   			  layer.msg(datas.message, {icon: 2});
       	   		  }
          	   });
    	   }, function(){
    		   layer.msg("已取消本次操作！", {icon: 6});
    	   });
         }
    </script>
</body>
</html>
